//
//  HMVisitorController.m
//  OC版本新浪微博
//
//  Created by 赵少朋赵少朋 on 17/1/18.
//  Copyright © 2017年 ITheima. All rights reserved.
//

#import "HMVisitorView.h"
#import "UIColor+Addition.h"

@interface HMVisitorView ()

@property (nonatomic, weak) UILabel *messageLabel;
@property (nonatomic, weak) UIImageView *iconView;

@end

@implementation HMVisitorView

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    
    if (self) {
     
//        self.backgroundColor = [UIColor colorWithRed:235 green:235 blue:235];
        [self setupUI];
        [self settingAnimation];
    }
    return self;
}

//判断是否更改数据
- (void)setupUIWithMessageLabelText:(NSString *)text imgName:(NSString *)imgName circleViewIsHidden:(BOOL)result {

    if (text == nil && imgName == nil) {
        
        [self settingAnimation];
    } else {
        self.messageLabel.text = text;
        self.iconView.image = [UIImage imageNamed:imgName];
    }
    [self.circleView setHidden:YES];
}

- (void)settingAnimation {

    CABasicAnimation *anim = [[CABasicAnimation alloc] init];
    anim.keyPath = @"transform.rotation";
    //动画角度
//    [anim setToValue: M_PI * 2];
    anim.toValue = @(M_PI * 2);
    //动画时长
    anim.duration = 20;
    
    anim.repeatCount = MAXFLOAT;
    [anim setRemovedOnCompletion:false];
//    anim.isRemovedOnCompletion
    
    
    [self.circleView.layer addAnimation:anim forKey:nil];
}

- (void)setupUI {
 
    UIImageView *circleView = [[UIImageView alloc] init];
    UIImageView *iconView = [[UIImageView alloc] init];
    UIImageView *maskIconView = [[UIImageView alloc] init];
    
    circleView.hidden = true;
    UILabel *messageLabel = [[UILabel alloc] init];
    
    UIButton *loginButton = [[UIButton alloc] init];
    UIButton *registerButton = [[UIButton alloc] init];
    
    circleView.image = [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
    iconView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    maskIconView.image = [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"];
    
    messageLabel.text = @"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
    messageLabel.numberOfLines = 0;
    messageLabel.textAlignment = UITextAlignmentCenter;
    messageLabel.font = [UIFont systemFontOfSize:14];
    
    [loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [loginButton setTitleColor:ThemeColor  forState:UIControlStateHighlighted];
    [loginButton setBackgroundImage:[UIImage imageNamed:@"common_button_white"]  forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loginClick:) forControlEvents:UIControlStateNormal];
    
    [registerButton setTitle:@"注册" forState:UIControlStateNormal];
    [registerButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [registerButton setTitleColor:ThemeColor  forState:UIControlStateHighlighted];
    [registerButton setBackgroundImage:[UIImage imageNamed:@"common_button_white"]  forState:UIControlStateNormal];
    [registerButton addTarget:self action:@selector(loginClick:) forControlEvents:UIControlStateNormal];
    
    [self addSubview:circleView];
    [self addSubview:iconView];
    [self addSubview:maskIconView];
    [self addSubview:messageLabel];
    [self addSubview:registerButton];
    [self addSubview:loginButton];
    
    [circleView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(self);
    }];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
    }];
    [maskIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
    }];
    
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(maskIconView.mas_bottom).offset(8);
        make.centerX.equalTo(self);
        make.width.offset(230);
    }];
    [loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(messageLabel.mas_bottom).offset(8);
        make.left.equalTo(messageLabel);
        make.width.offset(100);
    }];
    [registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(loginButton);
        make.right.equalTo(messageLabel);
        make.width.offset(100);
    }];
    
    self.circleView = circleView;
    self.iconView = iconView;
    self.messageLabel = messageLabel;
}

#pragma mark -- 登陆按钮点击事件
- (void)loginClick:(UIButton *)button {

    
    
}

@end
